package com.gmall.console.model;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;

/**
 * @description: 自动生成数据层代码
 * @author: Jone
 * @create: 2024-05-27
 */
public class CodeGenerator {

    private static String URL = "jdbc:mysql:///mallData";
    private static String USER_NAME = "root";
    private static String PWD = "12345678";
    private static Path PATH = Paths.get(System.getProperty("user.dir"));

    /**
    public static void main(String[] args) {
        FastAutoGenerator.create(URL, USER_NAME, PWD)
                .globalConfig(builder -> builder
                        .author("Jone")
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
                        .commentDate("yyyy-MM-dd")
                )
                .packageConfig(builder -> builder
                        .parent("com.gmall.console")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .xml("mapper.xml")
                )
                .strategyConfig(builder -> builder
                        .entityBuilder()
                        .enableLombok()
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }*/

    public static void main(String[] args) {
        FastAutoGenerator.create(URL, USER_NAME, PWD)
                .globalConfig(builder -> {
                    builder.author("Jone") // 设置作者
                            .enableSpringdoc() // 开启springdoc，用于swagger3
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir( PATH + "/src/main/java"); // 指定输出目录
                })
                .packageConfig(builder ->
                        builder.parent("com.gmall.console") // 设置父包名
                                .moduleName("system") // 设置父包模块名
                                .pathInfo(Collections.singletonMap(OutputFile.xml, PATH + "/src/main/resources/mapper")) // 设置mapperXml生成路径
                )
                .strategyConfig(builder ->
                        builder.addInclude("T_SNOWFLAKE") // 设置需要生成的表名
                                .addTablePrefix("t_", "c_") // 设置过滤表前缀
                )
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
